#ifndef SIP_DLGADAPTOR_BASE_HPP__
#define SIP_DLGADAPTOR_BASE_HPP__

#include "SipGDServiceConfigure.hpp"
#include "SipDialogHandle.hpp"
//#include "SipUserAgent.hpp"

//#define RESPONSE_OK 200

#define FailedReason(r, c) r


namespace wtsip{

class CSipSessionHandle;
class CSipSessionBase;
class CSipGDService;


class WTGD_SIPSRV_PUBLIC CSipSessionHandle{

public:

    virtual bool onSuccess(SipMessage& msg, CSipSessionBase& sb) = 0;

    virtual bool onFailed(SipMessage& msg, CSipSessionBase& sb) = 0;

    virtual bool onTrying(SipMessage& msg, CSipSessionBase& sb) = 0;

    virtual bool onDestroy(CSipSessionBase& sb) = 0;

};

//
class WTGD_SIPSRV_PUBLIC CSipSessionBase
{
public:

    typedef enum {
        FailedReason(Unknown, XXX) = -1,
        FailedReason(Trying, 100),
        FailedReason(RespseOK, 200),
        FailedReason(Error, 400),
        FailedReason(UnAuth, 401),
        FailedReason(Rejected, 403),
        FailedReason(NonUser, 404),
        FailedReason(UnProxyAuth, 407),
        FailedReason(ReqTimeout, 408),
        FailedReason(NonTrans, 481),
        FailedReason(ReqEnded, 487),
        MAXREASON
    } EFailReason;

public:
    //CSipSessionBase(CSipGDService& srv);

    CSipSessionBase(CSipGDService& srv, CSipClnTransaction& clntran);

    CSipSessionBase(CSipGDService& srv, CSipSrvTransaction& srvtran);

    CSipSessionBase(CSipGDService& srv, CSipDialogBase& dlg);

    virtual ~CSipSessionBase();

    //bool setRemoteUri(const resip::Uri& uri);

    //bool setLocalUri(const resip::Uri& uri);    

    virtual bool start(const std::string& body) = 0;

    virtual bool stop() = 0;

    virtual const resip::Data& getID();

    virtual const resip::Uri& getRemoteUri();

    virtual const resip::Uri& getLocalUri();

    virtual bool registerHandle(CSipSessionHandle* handle);

    virtual bool unregisterHandle(CSipSessionHandle* handle);

    virtual bool messageDresser(SipMessage& msg) = 0;

    virtual bool destroy();

    ///////////////// static methods  //////////////

    static resip::Mime& getMimeType();

    static EFailReason getReasonbyCode(int code);

    static int getCodebyReason(EFailReason reason);

protected:

    virtual bool onDestroy() = 0;

    virtual bool handleSuccess(SipMessage& msg);

    virtual bool handleFailed(SipMessage& msg);

    virtual bool handleTrying(SipMessage& msg);

    virtual bool handleDestroy();

protected:

    CSipGDService& m_service;

    resip::Uri m_RemoteUri;

    resip::Uri m_LocalUri;

    CSipDialogBase* m_dialog;

    CSipClnTransaction* m_clnTran;

    CSipSrvTransaction* m_srvTran;

    std::list<CSipSessionHandle*> m_handleList;

    resip::Data m_id;

    static int s_ReasonCode[MAXREASON];

    //static resip::Mime* s_mimeType;
};




}//namespace


#undef FailedReason

#endif

